﻿using System;
using System.Windows;
using System.Windows.Markup;
using System.IO;
using System.Xaml;

namespace WpfApp1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()//:this("App.xaml")
        {
            InitializeComponent();
        }

        public MainWindow(string xamlFile)
        {
            this.Height = this.Width = 350;
            this.Left = this.Top = 50;
            this.Title = "Loaded Xaml.";

            //主要是把.xaml文件描述的窗体加载到创建的窗体中
            DependencyObject rootElement;

            using (FileStream fs = new FileStream(xamlFile, FileMode.Open))
            {
                rootElement = (DependencyObject)System.Windows.Markup.XamlReader.Load(fs);//(DependencyObject)XamlReader.Load(fs);
                
            }
            this.Content = rootElement;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            DependencyObject rootElement;

            using (FileStream fs = new FileStream("App.xaml", FileMode.Open))
            {
                rootElement = (DependencyObject)System.Windows.Markup.XamlReader.Load(fs);//(DependencyObject)XamlReader.Load(fs);

            }
            this.Content = rootElement;
        }
    }
}
